package org.gienah.harness.artifacts;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.core.io.Resource;

/**
 * @author Santiago L. Valdarrama
 */
public class MockConfigurableApplicationContext
		implements ConfigurableApplicationContext {

	private Map<String, Object> beans;

	public MockConfigurableApplicationContext() {
		this.beans = new HashMap<String, Object>();
	}

	public void addBean(final String name, final Object bean) {
		this.beans.put(name, bean);
	}

	public Object getBean(final String name)
			throws BeansException {

		Object bean = this.beans.get(name);

		if (bean == null) {
			throw new NoSuchBeanDefinitionException(name);
		}

		return bean;
	}

	@SuppressWarnings("unchecked")
	public Map getBeansOfType(final Class type)
			throws BeansException {

		Map result = new HashMap();
		for (String bean : this.beans.keySet()) {
			if (this.beans.get(bean).getClass() == type) {
				result.put(bean, this.beans.get(bean));
			}
		}

		return result;
	}

	public boolean containsBean(final String bean) {
		return this.beans.containsKey(bean);
	}

	public void addBeanFactoryPostProcessor(final BeanFactoryPostProcessor processor) {
	}

	public void close() {
	}

	public ConfigurableListableBeanFactory getBeanFactory()
			throws IllegalStateException {
		return null;
	}

	public boolean isActive() {
		return false;
	}

	public void refresh()
			throws BeansException, IllegalStateException {
	}

	public void registerShutdownHook() {
	}

	public void setParent(final ApplicationContext context) {
	}

	public AutowireCapableBeanFactory getAutowireCapableBeanFactory()
			throws IllegalStateException {
		return null;
	}

	public String getDisplayName() {
		return null;
	}

	public ApplicationContext getParent() {
		return null;
	}

	public long getStartupDate() {
		return 0;
	}

	public boolean containsBeanDefinition(final String beanName) {
		return false;
	}

	public int getBeanDefinitionCount() {
		return 0;
	}

	public String[] getBeanDefinitionNames() {
		return null;
	}

	@SuppressWarnings("unchecked")
	public String[] getBeanNamesForType(final Class type) {
		return null;
	}

	@SuppressWarnings("unchecked")
	public String[] getBeanNamesForType(final Class type, final boolean includePrototypes, final boolean allowEagerInit) {
		return null;
	}

	@SuppressWarnings("unchecked")
	public Map getBeansOfType(final Class type, final boolean includePrototypes, final boolean allowEagerInit)
			throws BeansException {
		return null;
	}

	public String[] getAliases(final String bean) {
		return null;
	}

	@SuppressWarnings("unchecked")
	public Object getBean(final String name, final Class type)
			throws BeansException {
		return null;
	}

	@SuppressWarnings("unchecked")
	public Class getType(final String bean)
			throws NoSuchBeanDefinitionException {
		return null;
	}

	public boolean isSingleton(final String bean)
			throws NoSuchBeanDefinitionException {
		return false;
	}

	public boolean containsLocalBean(final String bean) {
		return false;
	}

	public BeanFactory getParentBeanFactory() {
		return null;
	}

	public String getMessage(final MessageSourceResolvable messageSourceResolvable, final Locale locale)
			throws NoSuchMessageException {
		return null;
	}

	public String getMessage(final String code, final Object[] args, final Locale locale)
			throws NoSuchMessageException {
		return null;
	}

	public String getMessage(final String code, final Object[] args, final String defaultMessage, final Locale locale) {
		return null;
	}

	public void publishEvent(final ApplicationEvent event) {
	}

	public Resource[] getResources(final String locationPattern) {
		return null;
	}

	public ClassLoader getClassLoader() {
		return null;
	}

	public Resource getResource(final String location) {
		return null;
	}

	public boolean isRunning() {
		return false;
	}

	public void start() {
	}

	public void stop() {
	}

}
